#pragma once
#include "ir.h"
#include "cfg.h"
#include "live_var.h"

namespace dead_code_elimination
{
    class DeadCodeEliminator
    {
    public:
        ir::IR Optimize(ir::IR& ir);

    private:
        bool OptimizeFunc(ir::Function& func);
        void RemoveDeadAllocInstr(ir::Function& func);
        void RemoveDeadFunc(ir::IR& ir);
        bool RemoveDeadInstr(
            cfg::CFG& cfg, live_var::FuncLiveness& func_liveness);
        bool RemoveDeadBlock(cfg::CFG& cfg);
        bool SimplifyControlFlow(cfg::CFG& cfg);
    };
}